<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="流水单号">
              <el-input v-model="form.orderSn" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="form.realname" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.username" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提交时间" width="236">
              <el-date-picker
                v-model="dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
              <el-button
                v-if="hasPermission('AdminFlowRefundRecordProvider.exportRefundRecordList')"
                plain
                type="primary"
                class="el-icon-download"
                @click="exportfun"
              >导出</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="orderSn" label="流水单号" />
        <el-table-column prop="realname" label="客户姓名" />
        <el-table-column prop="username" label="客户手机号" >
           <template slot-scope="scope">{{ scope.row.username|phonereg }}</template>
        </el-table-column>
        <el-table-column prop="payType" label="付款方式" />
        <el-table-column prop="amendmentAgo" label="修改前金额" />
        <el-table-column prop="amendmentLater" label="修改后金额" />
        <el-table-column prop="amendmentAmount" label="修改金额">
          <template slot-scope="scope">
            <div
              v-if="scope.row.amendmentAmount>0"
              style="color:green"
            >{{ scope.row.refundType==0?'增款扣除杂费':'增款杂费' }} ：{{ scope.row.amendmentAmount }}</div>
            <div
              v-else
              style="color:red"
            >{{ scope.row.refundType==0?'退款扣除杂费':'退款杂费' }} ：{{ -scope.row.amendmentAmount }}</div>
            <!-- <div>
                            退款杂费：新增字段
            </div>-->
          </template>
        </el-table-column>
        <el-table-column prop="createdAt" label="修改时间" />
        <el-table-column prop="msg" label="备注" />
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { flowRefundRecordList } from "@/api/runWaterMoney";
import { exportfile } from "@/api/commjs/exprot";
export default {
  name: "RunWaterMoneyIndex",
  filters: {
    cardType: function(e) {
      return window.helper.cardType(String(e));
    },
    getTime(e) {
      var now = new Date(e);
      var year = now.getFullYear();
      var month = now.getMonth() + 1;
      var date = now.getDate();
      return year + "-" + month + "-" + date;
    }
  },
  data() {
    return {
      dates: null,
      tableLoading: true,
      form: {
        createdAtBegin: null,
        createdAtEnd: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  inject: ["reload"],
  mounted() {
    this.getList(this.listForm);
  },
  methods: {
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    exportfun() {
      exportfile(
        "com.mmk.reservation.api.AdminFlowRefundRecordProvider/1.0.0/exportRefundRecordList.html",
        this.form
      );
    },
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      if (this.dates != null) {
        if (this.dates.length) {
          this.form.createdAtBegin = this.dates[0];
          this.form.createdAtEnd = this.dates[1];
        }
      } else {
        this.form.createdAtBegin = null;
        this.form.createdAtEnd = null;
      }
      console.log(this.form);
      this.getList(this.form);
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      flowRefundRecordList(datas)
        .then(res => {
          if (!res.data.code) {
            // this.reload()
            console.log(res);
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    // 路由跳转
    toRoutes(e, userId) {
      const route = { name: e, query: { userId: userId } };
      this.$router.push(route);
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
